﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using EkStudio.Com.UI.Interface;
using EkStudio.com.bean.xml.BillMultiple;
using EkStudio.com.ui.unitbill.property;
using DevExpress.XtraEditors.Controls;
using EkStudio.com.ui.unitbill.property.Event;
using EkStudio.com.ui.unitbill.BillMultiple;
using EkStudio.com.bean.xml.RootInterface.Plugin;
using EkStudio.com.bean.xml.Unit;
using DevExpress.XtraTab;
using EkStudio.com.bean.xml.BillModule;
using EkStudio.com.bean.xml.RootInterface.Field;
using EkStudio.com.bean.xml.RootInterface.DataSource;
using EkStudio.com.common.unit;
using EkStudio.com.bean.xml.RootInterface.FieldEvent;
using EkStudio.com.bean.xml.reflection.JAXB;
using System.Xml;
using EkStudio.com.common.clipboard;

namespace EkStudio.com.ui.unitbill
{
    public partial class BillMultipleUnitPanel :XtraUserControl, ProjectUnitBillInterface
    {
        private log4net.ILog logger = log4net.LogManager.GetLogger(typeof(BillMultipleUnitPanel));


        private bool readOnly = false;
        private bool save = true;
        private ProjectRootPanel RootPanel = null;
        private ProjectUnitBillInterface ParentUnit = null;
        private List<ProjectUnitBillInterface> SubjectUnit = new List<ProjectUnitBillInterface>();//子面板

        private BillMultipleItem MItem = null;


        //属性面板
        private ModuleUiGroupProperty GroupProperty = null;
        private ModuleUiFieldProperty FieldProperty = null;
        private ModuleUiEventProperty EventProperty = null;
        private ModuleUiJScriptProperty JScriptPropery = null;
        private ModuleUiJavaProperty JavaProperty = null;

        //当前选中的groupItem
        private BillUiGroupItems SelectGroup = null;
        private bool moveing = false;



        public BillMultipleUnitPanel(BillMultipleItem it,ProjectRootPanel Root, bool _readOnly)
        {
            InitializeComponent();
            MItem = it;
            RootPanel = Root;
            ReadOnly = _readOnly;
            InitBillModule();
        }
        /// <summary>
        /// 初始化面板
        /// </summary>
        private void InitBillModule()
        {
            ModPropertyGrid.SelectedObject = new MultipleModeToProperty(MItem);
            ModPropertyGrid.Refresh();
            //初始目录结构
            if (RootPanel.MenuItem.Business != null && RootPanel.MenuItem.Business.Modules != null
                && RootPanel.MenuItem.Business.Modules.Count > 0)
            {
                ModRepositoryMenuListEdit.Items.Clear();
                for (int i = 0; i < RootPanel.MenuItem.Business.Modules.Count; i++)
                {
                    CheckedListBoxItem item = new CheckedListBoxItem(RootPanel.MenuItem.Business.Modules[i].Caption, RootPanel.MenuItem.Business.Modules[i].Caption);
                    ModRepositoryMenuListEdit.Items.Add(item);
                }
            }

            //字段组属性页面
            GroupProperty = new ModuleUiGroupProperty(MItem, RootPanel, this);
            GroupProperty.Dock = DockStyle.Fill;
            GroupProperty.Visible = true;
            GroupProperty.CaptionChanged += GroupCaptionChanged;
            GroupPage.Controls.Add(GroupProperty);
            //字段属性页面
            FieldProperty = new ModuleUiFieldProperty(MItem, RootPanel, this);
            FieldProperty.Dock = DockStyle.Fill;
            FieldProperty.Visible = true;
            FieldProperty.CaptionChanged += GroupCaptionChanged;
            FieldPage.Controls.Add(FieldProperty);
            //事件属性页面
            EventProperty = new ModuleUiEventProperty(MItem, RootPanel, this);
            EventProperty.Dock = DockStyle.Fill;
            EventProperty.Visible = true;
            EventProperty.CaptionChanged += GroupCaptionChanged;
            EventPage.Controls.Add(EventProperty);
            //脚本属性页面
            JScriptPropery = new ModuleUiJScriptProperty(MItem, RootPanel, this);
            JScriptPropery.Dock = DockStyle.Fill;
            JScriptPropery.Visible = true;
            JScriptPropery.CaptionChanged += GroupCaptionChanged;
            JScriptPage.Controls.Add(JScriptPropery);

            //扩展代码属性
            JavaProperty = new ModuleUiJavaProperty(MItem, RootPanel, this);
            JavaProperty.Dock = DockStyle.Fill;
            JavaProperty.CaptionChanged += GroupCaptionChanged;
            JavaPage.Controls.Add(JavaProperty);



            //只读情况
            para_row_caption.Properties.ReadOnly = readOnly;
            para_row_key.Properties.ReadOnly = readOnly;
            para_row_dataType.Properties.ReadOnly = readOnly;
            para_row_notnull.Properties.ReadOnly = readOnly;
            para_row_defaultValue.Properties.ReadOnly = readOnly;

            source_row_caption.Properties.ReadOnly = readOnly;
            source_row_data.Properties.ReadOnly = readOnly;
            source_row_key.Properties.ReadOnly = readOnly;


            //初始化各内容
            initGroup();
            initField();
            initParam();
            initEvent();
            initSoruce();
            initJScript();
            initJava();
        }


        #region 事件注册


        /// <summary>
        /// 字段标签改变触发事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GroupCaptionChanged(object sender, PropertyDataEvent e)
        {
            XtraTabPage tab = PageTabControl.SelectedTabPage;
            if(tab.Controls[0] is ListView)
            {
                ListView view = tab.Controls[0] as ListView;
                ListViewItem it = view.SelectedItems[0];
                it.Text = (string)e.Value;
            }
            
        }
        /// <summary>
        /// 脚本处理弹出脚本界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ParamRepositoryPemitJScript_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            BillMultipleParamToProperty bean = ParamPropertyGrid.SelectedObject as BillMultipleParamToProperty;
            if (e.Button.Kind == ButtonPredefines.Ellipsis)
            {
                
                if (bean != null)
                {
                    BillExpandJavaCodeItem js = null;
                    if (bean.DefaultValue != "")
                    {
                        if (MItem.ExpandCode != null && MItem.ExpandCode.JavaPlugin != null && MItem.ExpandCode.JavaPlugin.JavaItem != null)
                        {
                            foreach(BillExpandJavaCodeItem it in MItem.ExpandCode.JavaPlugin.JavaItem)
                            {
                                if(it.Key == bean.DefaultValue)
                                {
                                    js = it;
                                    break;
                                }
                            }
                        }
                    }
                    if (js == null)
                    {
                        js = new BillExpandJavaCodeItem();
                        js.Caption = bean.Item.Caption;
                        js.Key = "JavaParamPermit_" + bean.Item.Key+"_Clazz";
                        js.Content = BeanUtil.getParamPermitJavaCode(bean.Item.Key, js.Key, MItem.getJavaPackage());
                        
                    }
                    ParamJavaPermitForm form = new ParamJavaPermitForm(bean.Item, RootPanel, this, js);
                    if(form.ShowDialog() == DialogResult.OK)
                    {
                        if (MItem.ExpandCode == null) MItem.ExpandCode = new BillExpandCodeRoot();
                        if (MItem.ExpandCode.JavaPlugin == null) MItem.ExpandCode.JavaPlugin = new BillExpandJavaCodeRoot();
                        if (MItem.ExpandCode.JavaPlugin.JavaItem == null) MItem.ExpandCode.JavaPlugin.JavaItem = new List<BillExpandJavaCodeItem>();
                        MItem.ExpandCode.JavaPlugin.addNode(js, MItem);
                        bean.Item.DefaultValue = js.Key;
                        initJava();
                        SaveStatus = false;
                    }
                }
            }
            else if(e.Button.Kind == ButtonPredefines.Delete)
            {
                if (bean != null&&bean.DefaultValue!="")
                {
                    if (XtraMessageBox.Show("您确认删除此参数处理方法？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        BillExpandJavaCodeItem js = null;
                        if (MItem.ExpandCode != null && MItem.ExpandCode.JavaPlugin != null && MItem.ExpandCode.JavaPlugin.JavaItem != null)
                        {
                            foreach (BillExpandJavaCodeItem it in MItem.ExpandCode.JavaPlugin.JavaItem)
                            {
                                if (it.Key == bean.DefaultValue)
                                {
                                    js = it;
                                    break;
                                }
                            }
                        }
                        if (js != null)
                        {
                            MItem.ExpandCode.JavaPlugin.removeNode(js);
                            initJava();
                        }
                        SaveStatus = false;
                        bean.DefaultValue = "";
                    }
                }
            }
            ParamPropertyGrid.Refresh();
        }


        /// <summary>
        /// 字段组列表按退格键盘回到分组字段
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FieldsListView_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.A && e.Control)//全选
            {
                

            }
            else if (e.KeyCode == Keys.Back && SelectGroup != null)
            {
                initGroup();
            }
        }

        /// <summary>
        /// 双击字段组
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FieldsListView_DoubleClick(object sender, EventArgs e)
        {
            if (FieldsListView.SelectedItems.Count == 1)
            {
                object temp = FieldsListView.SelectedItems[0].Tag;
                if (temp is BillUiGroupItems)
                {
                    SelectGroup = (BillUiGroupItems)temp;
                    initField();
                }
            }
        }

        /// <summary>
        /// 字段选择
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FieldsListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (moveing) return;
            if (FieldsListView.SelectedItems != null && FieldsListView.SelectedItems.Count > 0)
            {
                object item = FieldsListView.SelectedItems[0].Tag;
                if(item is BillUiGroupItems)
                {
                    TabChangeControl.SelectedTabPage = GroupPage;
                    GroupProperty.SelectObject = new BillUiGroupToProperty(item as BillUiGroupItems);
                    AttTabControl.SelectedTabPageIndex = 0;
                }else if(item is BillUiFieldsItem)
                {
                    TabChangeControl.SelectedTabPage = FieldPage;
                    FieldProperty.SelectField = new BillUiFieldToProperty(item as BillUiFieldsItem,SelectGroup);
                    AttTabControl.SelectedTabPageIndex = 0;
                }
            }
        }

        /// <summary>
        /// 参数选择事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ParamListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            
        }
        /// <summary>
        /// choose页面切换事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PageTabControl_SelectedPageChanged(object sender, TabPageChangedEventArgs e)
        {
            XtraTabPage page = PageTabControl.SelectedTabPage;
            if(page.Controls[0] is ListView)
            {
                ListView view = page.Controls[0] as ListView;
                view.ContextMenuStrip = FieldPopMenu;
            }
            TabChangeControl.SelectedTabPage = DefaultPage;
        }

        /// <summary>
        /// 数据源属性事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DataListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DataListView.SelectedItems.Count > 0)
            {
                ListViewItem view = DataListView.SelectedItems[0];
                if(view.Tag is BillSourceTabItems)
                {
                    AttTabControl.SelectedTabPageIndex = 0;
                    TabChangeControl.SelectedTabPage = DataPage;
                    SourcePropertyGrid.SelectedObject = new BillMultipleSourceToProperty(view.Tag as BillSourceTabItems);
                }
            }
        }
        /// <summary>
        /// 事件选择属性
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EventListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (EventListView.SelectedItems.Count > 0)
            {
                ListViewItem view = EventListView.SelectedItems[0];
                if(view.Tag is BillDataFillItem)
                {
                    BillDataFillItem it = view.Tag as BillDataFillItem;
                    AttTabControl.SelectedTabPageIndex = 0;
                    TabChangeControl.SelectedTabPage = EventPage;
                    EventProperty.SelectObject = new BillUiEventToProperty(it);
                }
            }
        }
        /// <summary>
        /// 脚本选择事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ScriptListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            
        }
        /// <summary>
        /// java选择事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void JavaListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            
        }

        /// <summary>
        /// 数据源属性按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SourceRepositoryDataEdit_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            BillMultipleSourceToProperty bean = SourcePropertyGrid.SelectedObject as BillMultipleSourceToProperty;
            if (bean != null)
            {
                RootPanel.AddConsoleText(bean.Item.Content, false);
                SourceConfigForm form = new SourceConfigForm(bean.Item, readOnly);
                if(form.ShowDialog() == DialogResult.OK)
                {
                    SaveStatus = false;
                }
            }
        }

        /// <summary>
        /// 参数caption改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ParamPropertyGrid_CellValueChanged(object sender, DevExpress.XtraVerticalGrid.Events.CellValueChangedEventArgs e)
        {
            if(e.Row.Properties.FieldName == "Caption")
            {
                GroupCaptionChanged(sender, new PropertyDataEvent("Caption", e.Value));
            }
            SaveStatus = false;
        }
        /// <summary>
        /// 数据源caption改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SourcePropertyGrid_CellValueChanged(object sender, DevExpress.XtraVerticalGrid.Events.CellValueChangedEventArgs e)
        {
            if(e.Row.Properties.FieldName == "Caption")
            {
                GroupCaptionChanged(sender, new PropertyDataEvent("Caption", e.Value));
            }
            SaveStatus = false;
        }


        #endregion


        #region bean属性


        /// <summary>
        /// 复制
        /// </summary>
        /// <param name="clazz">复制后的clazz</param>
        /// <returns></returns>
        public bool Copy(out object clazz)
        {
            bool val = false;
            clazz = null;

            return val;
        }
        public string BillKey
        {
            get
            {
                return MItem.getKey();
            }
        }

        public bool isSubUnitBill
        {
            get
            {
                return false;
            }
        }

        public ProjectUnitBillInterface ParentPage
        {
            get
            {
                return ParentUnit;
            }

            set
            {
                ParentUnit = value;
            }
        }

        public bool ReadOnly
        {
            get
            {
                return readOnly;
            }

            set
            {
                readOnly = value;
            }
        }

        public bool SaveStatus
        {
            get
            {
                return save;
            }

            set
            {
                save = value;
                RootPanel.SaveStatus = value;
            }
        }

        public List<ProjectUnitBillInterface> SubjectPage
        {
            get
            {
                return SubjectUnit;
            }
        }

        public void AddSubjectBill(ProjectUnitBillInterface bill)
        {
            if (!SubjectUnit.Contains(bill))
            {
                bill.ParentPage = this;
                SubjectUnit.Add(bill);
            }
        }

        public bool close()
        {
            bool result = true;
            if (!save || !isSubSaveStatus())
            {
                DialogResult dialog = XtraMessageBox.Show("当前数据已更改是否保存?", "提示", MessageBoxButtons.YesNoCancel);
                if (dialog == DialogResult.Yes)
                {
                    saveData(true);
                    result = true;
                }
                else if (dialog == DialogResult.No)
                {
                    result = true;
                }
                else
                {
                    result = false;
                }
            }

            if (result)
            {
                //释放模块占用
                try
                {
                    RootPanel.Http.ReleaseModule(MItem.getKey(), MItem.getCaption(), ProjectUtil.TYPE_BILL_MULTIPLE);
                }
                catch (Exception e)
                {
                    RootPanel.AddConsoleText("页面关闭失败", true);
                    logger.Error("页面关闭失败", e);
                }

            }

            return result;
        }

        public bool ContainSubject(ProjectUnitBillInterface bill)
        {
            return SubjectUnit.Contains(bill);
        }

        public void RemoveSubjectBill(ProjectUnitBillInterface bill)
        {
            if (SubjectUnit.Contains(bill))
            {
                bill.ParentPage = null;
                SubjectUnit.Remove(bill);
            }
        }

        /// <summary>
        /// 判定子页面保存状态
        /// </summary>
        /// <returns></returns>
        private bool isSubSaveStatus()
        {
            bool result = true;
            if (SubjectUnit.Count > 0)
            {
                for (int i = 0; i < SubjectUnit.Count; i++)
                {
                    if (!SubjectUnit[i].SaveStatus)
                    {
                        result = false;
                        break;
                    }
                }
            }

            return result;
        }

        #endregion

        public void saveData(bool updateParent)
        {
            if (!readOnly && (!save || !isSubSaveStatus()))
            {
                if (!isSubSaveStatus())
                {
                    //先保存子页面
                    foreach (ProjectUnitBillInterface subPage in SubjectUnit)
                    {
                        subPage.saveData(false);
                    }
                }
                MItem.autoInitLanguage(RootPanel.ProjectVersion);
                MItem.MultProperties.RootVersion = BeanUtil.VERSION;
                MItem.MultProperties.Owner.LastMender = RootPanel.UserInfo.UserName;
                MItem.MultProperties.Owner.LastModified = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");

                JAXBContext<BillMultipleItem> jaxb = new JAXBContext<BillMultipleItem>();

                string xml = jaxb.marshal(MItem, true);
                string result = RootPanel.Http.SaveXmlBean(MItem.getKey(), ProjectUtil.TYPE_BILL_MULTIPLE, xml);

                XmlDocument docXml = new XmlDocument();
                try
                {
                    docXml.LoadXml(result);
                    XmlElement root = docXml.DocumentElement;
                    XmlNode node = root.SelectSingleNode("result");
                    if (node.InnerText == "0")
                    {
                        RootPanel.AddConsoleText(string.Format("保存模块[{0}]成功", MItem.getCaption()), false);
                    }
                    else
                    {
                        RootPanel.AddConsoleText(string.Format("保存模块[{0}]失败", MItem.getCaption()), false);
                    }
                }
                catch (Exception e)
                {
                    RootPanel.AddConsoleText(string.Format("保存模块[{0}]失败", MItem.getCaption()), false);
                    logger.Error("保存失败", e);
                }

                save = true;
                if (updateParent) RootPanel.SaveStatus = true;
                ModPropertyGrid.Refresh();
            }
        }


        #region 初始化加载数据
        /// <summary>
        /// 初始化字段组
        /// </summary>
        private void initGroup()
        {
            if (MItem.UiField == null)
            {
                MItem.UiField = new BillUiGroupRoot();
                MItem.UiField.FieldsProperties = new List<BillUiGroupItems>();
            }
            FieldsListView.Items.Clear();
            if (MItem.UiField.FieldsProperties.Count > 0)
            {
                //ListViewItem("主要字段", 0);
                for (int i = 0; i < MItem.UiField.FieldsProperties.Count; i++)
                {
                    BillUiGroupItems group = MItem.UiField.FieldsProperties[i];
                    ListViewItem ViewIt = new ListViewItem(group.Caption, 0);
                    ViewIt.Tag = group;
                    FieldsListView.Items.Add(ViewIt);
                }
            }
            if (SelectGroup != null)
            {
                SelectGroup = null;
                HideFieldProperty();
            }
            
        }

        
        /// <summary>
        /// 初始化字段数据
        /// </summary>
        private void initField()
        {
            if (SelectGroup != null)
            {
                FieldsListView.Items.Clear();
                if (SelectGroup.Fields != null && SelectGroup.Fields.Count > 0)
                {
                    foreach(BillUiFieldsItem field in SelectGroup.Fields)
                    {
                        ListViewItem ViewIt = new ListViewItem(field.Caption, 1);
                        ViewIt.Tag = field;
                        FieldsListView.Items.Add(ViewIt);
                    }
                }
            }
           
            HideFieldProperty();
        }
        /// <summary>
        /// 初始化参数
        /// </summary>
        private void initParam()
        {
            if (MItem.ParamProperties != null && MItem.ParamProperties.ParamItem != null)
            {
                foreach(BillMultipleParamItem it in MItem.ParamProperties.ParamItem)
                {
                    ListViewItem ViewIt = new ListViewItem(it.Caption, 7);
                    ViewIt.Tag = it;
                    ParamListView.Items.Add(ViewIt);
                }
            }
            ParamListView.Tag = typeof(BillMultipleParamItem);
        }
        /// <summary>
        /// 初始化数据源
        /// </summary>
        private void initSoruce()
        {
            if(MItem.DataSource != null && MItem.DataSource.TableItems != null && MItem.DataSource.TableItems.Count > 0)
            {
                foreach(BillSourceTabItems tb in MItem.DataSource.TableItems)
                {
                    ListViewItem ViewIt = new ListViewItem(tb.Caption, 6);
                    ViewIt.Tag = tb;
                    DataListView.Items.Add(ViewIt);
                }
            }
            DataListView.Tag = typeof(BillSourceTabItems);
        }

        private void initEvent()
        {
            EventListView.Items.Clear();
            if (MItem.DataFill == null)
            {
                MItem.DataFill = new BillDataFillRoot();
                MItem.DataFill.LinkEvents = new List<BillDataFillItem>();
            }
            if (MItem.DataFill.LinkEvents == null)
            {
                MItem.DataFill.LinkEvents = new List<BillDataFillItem>();
            }
            if (MItem.DataFill.LinkEvents.Count > 0)
            {
                for (int i = 0; i < MItem.DataFill.LinkEvents.Count; i++)
                {
                    BillDataFillItem it = MItem.DataFill.LinkEvents[i];
                    ListViewItem ViewIt = new ListViewItem(it.Caption, 5);
                    ViewIt.Tag = it;
                    EventListView.Items.Add(ViewIt);
                }
            }
            EventListView.Tag = typeof(BillDataFillItem);
        }
        /// <summary>
        /// 初始化脚本
        /// </summary>
        private void initJScript()
        {
            ScriptListView.Items.Clear();
            if (MItem.ExpandCode == null)
            {
                MItem.ExpandCode = new BillExpandCodeRoot();
            }
            if (MItem.ExpandCode.Jscript == null)
            {
                MItem.ExpandCode.Jscript = new BillExpandJsCodeRoot();
            }
            if (MItem.ExpandCode.Jscript.Item == null)
            {
                MItem.ExpandCode.Jscript.Item = new List<BillExpandJsCodeItem>();
            }

            if (MItem.ExpandCode.Jscript.Item.Count > 0)
            {
                for (int i = 0; i < MItem.ExpandCode.Jscript.Item.Count; i++)
                {
                    BillExpandJsCodeItem JItem = MItem.ExpandCode.Jscript.Item[i];
                    ListViewItem ViewIt = new ListViewItem(JItem.Caption, 2);
                    ViewIt.Tag = JItem;
                    ScriptListView.Items.Add(ViewIt);
                }
            }
            ScriptListView.Tag = typeof(BillExpandJsCodeItem);
        }
        /// <summary>
        /// 初始化扩展代码
        /// </summary>
        private void initJava()
        {
            JavaListView.Clear();
            if (MItem.ExpandCode == null)
            {
                MItem.ExpandCode = new BillExpandCodeRoot();
            }
            if (MItem.ExpandCode.JavaPlugin == null)
            {
                MItem.ExpandCode.JavaPlugin = new BillExpandJavaCodeRoot();
            }
            if (MItem.ExpandCode.JavaPlugin.JavaItem == null)
            {
                MItem.ExpandCode.JavaPlugin.JavaItem = new List<BillExpandJavaCodeItem>();
            }
            if (MItem.ExpandCode.JavaPlugin.JavaItem.Count > 0)
            {
                for (int i = 0; i < MItem.ExpandCode.JavaPlugin.JavaItem.Count; i++)
                {
                    BillExpandJavaCodeItem it = MItem.ExpandCode.JavaPlugin.JavaItem[i];
                    ListViewItem ViewIt = new ListViewItem(it.Caption, 3);
                    ViewIt.Tag = it;
                    JavaListView.Items.Add(ViewIt);
                }
            }
            JavaListView.Tag = typeof(BillExpandJavaCodeItem);
        }


        private void HideFieldProperty()
        {
            TabChangeControl.SelectedTabPageIndex = 0;
        }



        #endregion

        class MultipleModeToProperty
        {
            private BillMultipleItem item = null;

            public MultipleModeToProperty(BillMultipleItem it)
            {
                item = it;
            }
            public string Caption
            {
                get { return item.getCaption(); }
            }
            public string Key
            {
                get { return item.getKey();}
            }

            public string GroupList
            {
                get { return item.MultProperties.GroupList; }
                set { item.MultProperties.GroupList = value; }
            }

            public string Creater
            {
                get { return item.MultProperties.Owner.Creater; }
            }
            public string Created
            {
                get { return item.MultProperties.Owner.Created; }
            }

            public string LastMender
            {
                get { return item.MultProperties.Owner.LastMender; }
            }

            public string LastModified
            {
                get { return item.MultProperties.Owner.LastModified; }
            }
        }


        #region 目录操作


        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FieldPopNewNode_Click(object sender, EventArgs e)
        {
            if (readOnly) return;
            bool success = false;
            if (PageTabControl.SelectedTabPage == FieldColTabPage)
            {
                if (SelectGroup != null)//新建字段
                {
                    BillUiFieldsItem field = new BillUiFieldsItem();
                    field.DataProperty = new BillUiFieldsDataProperty();
                    field.EditBorder = new BillUiFieldsEditBorderProperty();
                    field.EditProperty = new BillUiFieldsEditProperty();
                    field.FormulaProperty = new BillUiFieldsFormulaProperty();
                    field.ViewBorder = new BillUiFieldsViewBorderProperty();
                    SelectGroup.addNode(field, MItem);
                    ListViewItem it = new ListViewItem(field.Caption, 1);
                    it.Tag = field;
                    FieldsListView.Items.Add(it);
                    it.Selected = true;
                    success = true;
                }
                else //新建分组
                {
                    BillUiGroupItems group = new BillUiGroupItems();
                    group.Fields = new List<BillUiFieldsItem>();
                    MItem.UiField.addNode(group, MItem);
                    ListViewItem it = new ListViewItem(group.Caption, 0);
                    it.Tag = group;
                    FieldsListView.Items.Add(it);
                    it.Selected = true;
                    success = true;
                }
            }else if(PageTabControl.SelectedTabPage == ParamTabPage)
            {
                BillMultipleParamItem it = new BillMultipleParamItem();
                if (MItem.ParamProperties == null) MItem.ParamProperties = new BillMultipleParamRoot();
                if (MItem.ParamProperties.ParamItem == null) MItem.ParamProperties.ParamItem = new List<BillMultipleParamItem>();
                MItem.ParamProperties.addNode(it,MItem);
                ListViewItem view = new ListViewItem(it.Caption, 7);
                view.Tag = it;
                ParamListView.Items.Add(view);
                view.Selected = true;
                success = true;

            }
            else if(PageTabControl.SelectedTabPage == SourceTabPage)
            {
                BillSourceTabItems it = new BillSourceTabItems();
                if (MItem.DataSource == null) MItem.DataSource = new BillSourceRoot();
                if (MItem.DataSource.TableItems == null) MItem.DataSource.TableItems = new List<BillSourceTabItems>();
                it.Key = "";
                it.Caption = "Unnamed";
                MItem.DataSource.TableItems.Add(it);
                ListViewItem view = new ListViewItem(it.Caption, 6);
                view.Tag = it;
                DataListView.Items.Add(view);
                view.Selected = true;
                success = true;
            }
            else if (PageTabControl.SelectedTabPage == EventTabPage)//填充事件
            {
                BillDataFillItem EventIt = new BillDataFillItem();
                if (MItem.DataFill == null) MItem.DataFill = new BillDataFillRoot();
                if (MItem.DataFill.LinkEvents == null) MItem.DataFill.LinkEvents = new List<BillDataFillItem>();
                MItem.DataFill.addNode(EventIt, MItem);
                ListViewItem it = new ListViewItem(EventIt.Caption, 5);
                it.Tag = EventIt;
                EventListView.Items.Add(it);
                it.Selected = true;
                success = true;
            }
            else if (PageTabControl.SelectedTabPage == JScriptTabPage)//脚本代码
            {
                BillExpandJsCodeItem js = new BillExpandJsCodeItem();

                MItem.ExpandCode.Jscript.addNode(js, MItem);
                ListViewItem it = new ListViewItem(js.Caption, 2);
                it.Tag = js;
                ScriptListView.Items.Add(it);
                it.Selected = true;
                success = true;
            }
            else if (PageTabControl.SelectedTabPage == JavaTabPage)//扩展代码
            {
                BillExpandJavaCodeItem java = new BillExpandJavaCodeItem();
                java.JavaPackage = string.Format("com.kootop.plugin.{0}", MItem.getJavaPackage());
                MItem.ExpandCode.JavaPlugin.addNode(java, MItem);
                ListViewItem it = new ListViewItem(java.Caption, 3);
                it.Tag = java;
                JavaListView.Items.Add(it);
                it.Selected = true;
                success = true;
            }
            if (success) SaveStatus = false;
        }

        /// <summary>
        /// 目录删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FieldPopDeleteNode_Click(object sender, EventArgs e)
        {
            if (readOnly) return;
            if (PageTabControl.SelectedTabPage == FieldColTabPage)
            {
                if (SelectGroup != null)//删除字段
                {
                    if (FieldsListView.SelectedItems.Count == 1)
                    {
                        DialogResult DR = XtraMessageBox.Show("您确认要删除当前选中字段吗?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (DR == DialogResult.Yes)
                        {
                            ListViewItem it = FieldsListView.SelectedItems[0];
                            BillUiFieldsItem field = (BillUiFieldsItem)it.Tag;
                            SelectGroup.removeNode(field);
                            it.Tag = null;
                            FieldsListView.Items.Remove(it);
                            field = null;
                            it = null;
                            HideFieldProperty();
                            SaveStatus = false;
                        }
                    }
                    else if (FieldsListView.SelectedItems.Count > 1)
                    {
                        DialogResult DR = XtraMessageBox.Show("您确认要删除当前选中字段吗?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (DR == DialogResult.Yes)
                        {
                            foreach(ListViewItem it in FieldsListView.SelectedItems)
                            {
                                BillUiFieldsItem field = (BillUiFieldsItem)it.Tag;
                                SelectGroup.removeNode(field);
                                it.Tag = null;
                                FieldsListView.Items.Remove(it);
                                field = null;
                            }
                            HideFieldProperty();
                            SaveStatus = false;
                        }
                    }
                }
                else //删除分组
                {
                    if (FieldsListView.SelectedItems.Count == 1)
                    {
                        DialogResult DR = XtraMessageBox.Show("您确认要删除当前选中分组吗?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (DR == DialogResult.Yes)
                        {
                            ListViewItem it = FieldsListView.SelectedItems[0];
                            BillUiGroupItems field = (BillUiGroupItems)it.Tag;
                            MItem.UiField.removeNode(field);
                            it.Tag = null;
                            FieldsListView.Items.Remove(it);
                            field = null;
                            it = null;
                            HideFieldProperty();
                            SaveStatus = false;
                        }
                    }
                }
            }
            else if(PageTabControl.SelectedTabPage == ParamTabPage)//删除参数
            {
                DialogResult DR = XtraMessageBox.Show("您确认要删除当前选中参数吗?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (DR == DialogResult.Yes)
                {
                    ListViewItem it = ParamListView.SelectedItems[0];
                    BillMultipleParamItem field = (BillMultipleParamItem)it.Tag;
                    MItem.ParamProperties.removeNode(field);
                    it.Tag = null;
                    ParamListView.Items.Remove(it);
                    field = null;
                    it = null;
                    HideFieldProperty();
                    SaveStatus = false;
                }
            }
            else if(PageTabControl.SelectedTabPage == SourceTabPage)//删除数据源
            {
                DialogResult DR = XtraMessageBox.Show("您确认要删除当前选中参数吗?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (DR == DialogResult.Yes)
                {
                    ListViewItem it = DataListView.SelectedItems[0];
                    BillSourceTabItems field = (BillSourceTabItems)it.Tag;
                    MItem.DataSource.TableItems.Remove(field);
                    it.Tag = null;
                    DataListView.Items.Remove(it);
                    field = null;
                    it = null;
                    HideFieldProperty();
                    SaveStatus = false;
                }
            }
            else if (PageTabControl.SelectedTabPage == EventTabPage)//填充事件
            {
                if (EventListView.SelectedItems.Count == 1)
                {
                    DialogResult DR = XtraMessageBox.Show("您确认要删除当前选中事件吗?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (DR == DialogResult.Yes)
                    {
                        ListViewItem it = EventListView.SelectedItems[0];
                        BillDataFillItem field = (BillDataFillItem)it.Tag;
                        MItem.DataFill.removeNode(field);
                        it.Tag = null;
                        EventListView.Items.Remove(it);
                        field = null;
                        it = null;
                        HideFieldProperty();
                        SaveStatus = false;
                    }
                }
            }
            else if (PageTabControl.SelectedTabPage == JScriptTabPage)//脚本代码
            {
                if (ScriptListView.SelectedItems.Count == 1)
                {
                    DialogResult DR = XtraMessageBox.Show("您确认要删除当前选中脚本吗?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    ListViewItem it = ScriptListView.SelectedItems[0];
                    BillExpandJsCodeItem js = it.Tag as BillExpandJsCodeItem;
                    MItem.ExpandCode.Jscript.removeNode(js);
                    it.Tag = null;
                    ScriptListView.Items.Remove(it);
                    js = null;
                    it = null;
                    HideFieldProperty();
                    SaveStatus = false;
                }
            }
            else if (PageTabControl.SelectedTabPage == JavaTabPage)//扩展代码
            {
                if (JavaListView.SelectedItems.Count == 1)
                {
                    DialogResult DR = XtraMessageBox.Show("您确认要删除当前选中脚本吗?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    ListViewItem it = JavaListView.SelectedItems[0];
                    BillExpandJavaCodeItem java = it.Tag as BillExpandJavaCodeItem;
                    MItem.ExpandCode.JavaPlugin.removeNode(java);
                    it.Tag = null;
                    JavaListView.Items.Remove(it);
                    java = null;
                    it = null;
                    HideFieldProperty();
                    SaveStatus = false;
                }
            }
        }

        /// <summary>
        /// 复制功能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FieldPopCopyNode_Click(object sender, EventArgs e)
        {
            if (PageTabControl.SelectedTabPage == FieldColTabPage)
            {
                if (SelectGroup != null)//复制字段
                {
                    if (FieldsListView.SelectedItems.Count > 0)
                    {
                        bool sccuess = true;
                        BillUiFieldsItem[] fields = new BillUiFieldsItem[FieldsListView.SelectedItems.Count];
                        int i = 0;
                        foreach (ListViewItem it in FieldsListView.SelectedItems)
                        {
                            try
                            {
                                BillUiFieldsItem Cp = (BillUiFieldsItem)((BillUiFieldsItem)it.Tag).Clone();
                                fields[i] = Cp;
                            }
                            catch (Exception ee)
                            {
                                logger.Error("字段不支持复制", ee);
                                RootPanel.AddConsoleText("字段不支持复制", true);
                                sccuess = false;
                            }
                            i++;
                        }
                        if (sccuess)
                        {
                            JClipboard.copy(fields);
                            RootPanel.AddConsoleText("复制字段Len==" + fields.Length, false);
                        }
                    }
                }
                else //新建分组
                {
                    if (FieldsListView.SelectedItems.Count > 0)
                    {
                        bool sccuess = true;
                        BillUiGroupItems[] groups = new BillUiGroupItems[FieldsListView.SelectedItems.Count];
                        for (int i = 0; i < FieldsListView.SelectedItems.Count; i++)
                        {
                            BillUiGroupItems it = (BillUiGroupItems)FieldsListView.SelectedItems[i].Tag;
                            try
                            {
                                BillUiGroupItems cp = (BillUiGroupItems)it.Clone();
                                groups[i] = cp;
                            }
                            catch (Exception ee)
                            {
                                logger.Error("字段组不支持复制", ee);
                                RootPanel.AddConsoleText("字段组不支持复制", true);
                                sccuess = false;
                            }
                        }
                        if (sccuess)
                        {
                            JClipboard.copy(groups);
                        }
                    }
                }
            }
            else if(PageTabControl.SelectedTabPage == ParamTabPage)
            {
                RootPanel.AddConsoleText("暂不支持复制", false);
            }else if(PageTabControl.SelectedTabPage == SourceTabPage)
            {
                RootPanel.AddConsoleText("暂不支持复制", false);
            }
            else if (PageTabControl.SelectedTabPage.Name == "EventTabPage")//填充事件
            {
                if (EventListView.SelectedItems.Count > 0)
                {
                    bool sccuess = true;
                    BillDataFillItem[] fills = new BillDataFillItem[EventListView.SelectedItems.Count];
                    for (int i = 0; i < EventListView.SelectedItems.Count; i++)
                    {
                        BillDataFillItem fill = EventListView.SelectedItems[i].Tag as BillDataFillItem;
                        try
                        {
                            fills[i] = fill.Clone() as BillDataFillItem;
                        }
                        catch (Exception ee)
                        {
                            logger.Error("填充事件不支持复制", ee);
                            RootPanel.AddConsoleText("填充事件不支持复制", true);
                            sccuess = false;
                            break;
                        }
                    }
                    if (sccuess)
                    {
                        JClipboard.copy(fills);
                    }
                }
            }
            else if (PageTabControl.SelectedTabPage.Name == "ScriptTabPage")//脚本代码
            {
                if (ScriptListView.SelectedItems.Count > 0)
                {
                    bool sccuess = true;
                    BillExpandJsCodeItem[] fills = new BillExpandJsCodeItem[ScriptListView.SelectedItems.Count];
                    for (int i = 0; i < ScriptListView.SelectedItems.Count; i++)
                    {
                        BillExpandJsCodeItem fill = ScriptListView.SelectedItems[i].Tag as BillExpandJsCodeItem;
                        try
                        {
                            fills[i] = fill.Clone() as BillExpandJsCodeItem;
                        }
                        catch (Exception ee)
                        {
                            logger.Error("脚本不支持复制", ee);
                            RootPanel.AddConsoleText("脚本不支持复制", true);
                            sccuess = false;
                            break;
                        }
                    }
                    if (sccuess)
                    {
                        JClipboard.copy(fills);
                    }
                }
            }
            else if (PageTabControl.SelectedTabPage.Name == "JavaTabPage")//扩展代码
            {
                if (JavaListView.SelectedItems.Count > 0)
                {
                    bool sccuess = true;
                    BillExpandJavaCodeItem[] fills = new BillExpandJavaCodeItem[JavaListView.SelectedItems.Count];
                    for (int i = 0; i < JavaListView.SelectedItems.Count; i++)
                    {
                        BillExpandJavaCodeItem fill = JavaListView.SelectedItems[i].Tag as BillExpandJavaCodeItem;
                        try
                        {
                            fills[i] = fill.Clone() as BillExpandJavaCodeItem;
                        }
                        catch (Exception ee)
                        {
                            logger.Error("脚本不支持复制", ee);
                            RootPanel.AddConsoleText("脚本不支持复制", true);
                            sccuess = false;
                            break;
                        }
                    }
                    if (sccuess)
                    {
                        JClipboard.copy(fills);
                    }
                }
            }
        }

        /// <summary>
        /// 粘贴功能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FieldPopPasteNode_Click(object sender, EventArgs e)
        {
            if (readOnly) return;
            if (!JClipboard.ContainData()) return;
            if (PageTabControl.SelectedTabPage == FieldColTabPage)
            {
                if (SelectGroup != null)//粘贴字段
                {
                    if (JClipboard.Paste()[0] is BillUiFieldsItem)
                    {
                        foreach (BillUiFieldsItem field in JClipboard.Paste())
                        {
                            SelectGroup.addNode(field, MItem);
                            ListViewItem it = new ListViewItem(field.Caption, 1);
                            it.Tag = field;
                            FieldsListView.Items.Add(it);
                        }
                        SaveStatus = false;
                        JClipboard.Clear();
                    }
                }
                else //新建分组
                {
                    if (JClipboard.Paste()[0] is BillUiGroupItems)
                    {
                        foreach (BillUiGroupItems group in JClipboard.Paste())
                        {
                            
                            MItem.UiField.addNode(group, MItem);
                            ListViewItem it = new ListViewItem(group.Caption, 0);
                            it.Tag = group;
                            FieldsListView.Items.Add(it);
                        }
                        SaveStatus = false;
                        JClipboard.Clear();
                    }
                }
            }
            else if (PageTabControl.SelectedTabPage == EventTabPage)//填充事件
            {
                if (JClipboard.Paste()[0] is BillDataFillItem)
                {
                    foreach (BillDataFillItem fill in JClipboard.Paste())
                    {
                        MItem.DataFill.addNode(fill, MItem);
                        ListViewItem it = new ListViewItem(fill.Caption, 5);
                        it.Tag = fill;
                        EventListView.Items.Add(it);
                    }
                    SaveStatus = false;
                    JClipboard.Clear();
                }
            }
            else if (PageTabControl.SelectedTabPage == JScriptTabPage)//脚本代码
            {
                if (JClipboard.Paste()[0] is BillExpandJsCodeItem)
                {
                    foreach (BillExpandJsCodeItem fill in JClipboard.Paste())
                    {
                        //MItem.DataFill.addNode(fill, MItem);
                        MItem.ExpandCode.Jscript.addNode(fill, MItem);
                        ListViewItem it = new ListViewItem(fill.Caption, 2);
                        it.Tag = fill;
                        ScriptListView.Items.Add(it);
                    }
                    SaveStatus = false;
                    JClipboard.Clear();
                }

            }
            else if (PageTabControl.SelectedTabPage == JavaTabPage)//扩展代码
            {
                if (JClipboard.Paste()[0] is BillExpandJavaCodeItem)
                {
                    foreach (BillExpandJavaCodeItem fill in JClipboard.Paste())
                    {
                        //MItem.DataFill.addNode(fill, MItem);
                        MItem.ExpandCode.JavaPlugin.addNode(fill, MItem);
                        ListViewItem it = new ListViewItem(fill.Caption, 2);
                        it.Tag = fill;
                        JavaListView.Items.Add(it);
                    }
                    SaveStatus = false;
                    JClipboard.Clear();
                }
            }
        }

        /// <summary>
        /// 上移
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FieldPopUpNode_Click(object sender, EventArgs e)
        {
            if (readOnly) return;
            moveing = true;
            if (FieldsListView.SelectedItems.Count != 1) return;
            if (PageTabControl.SelectedTabPage == FieldColTabPage)
            {
                if (SelectGroup != null)//字段上移
                {
                    ListViewItem view = FieldsListView.SelectedItems[0];
                    BillUiFieldsItem field = view.Tag as BillUiFieldsItem;
                    int index = FieldsListView.Items.IndexOf(view);
                    if (index > 0)
                    {
                        SelectGroup.moveUp(field);
                        ListViewItem PevView = FieldsListView.Items[index - 1];
                        PevView.Tag = SelectGroup.Fields[index - 1];
                        PevView.Text = (PevView.Tag as BillUiFieldsItem).Caption;
                        view.Tag = SelectGroup.Fields[index];
                        view.Text = (view.Tag as BillUiFieldsItem).Caption;
                        PevView.Selected = true;
                        view.Selected = false;
                        SaveStatus = false;
                    }
                }
                else//字段组上组
                {
                    ListViewItem view = FieldsListView.SelectedItems[0];
                    BillUiGroupItems group = view.Tag as BillUiGroupItems;
                    int index = FieldsListView.Items.IndexOf(view);
                    if (index > 0)
                    {
                        MItem.UiField.moveUp(group);
                        ListViewItem PevView = FieldsListView.Items[index - 1];
                        PevView.Tag = MItem.UiField.FieldsProperties[index - 1];
                        PevView.Text = (PevView.Tag as BillUiGroupItems).Caption;
                        view.Tag = MItem.UiField.FieldsProperties[index];
                        view.Text = (view.Tag as BillUiGroupItems).Caption;
                        PevView.Selected = true;
                        view.Selected = false;
                        SaveStatus = false;
                    }
                }

            }
            moveing = false;
        }


        /// <summary>
        /// 下移
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FieldPopDownNode_Click(object sender, EventArgs e)
        {
            if (readOnly) return;
            moveing = true;
            if (PageTabControl.SelectedTabPage == FieldColTabPage)
            {
                if (SelectGroup != null)//字段上移
                {
                    ListViewItem view = FieldsListView.SelectedItems[0];
                    BillUiFieldsItem field = view.Tag as BillUiFieldsItem;
                    int index = FieldsListView.Items.IndexOf(view);
                    if (index < FieldsListView.Items.Count - 1)
                    {
                        SelectGroup.moveDown(field);
                        ListViewItem LastView = FieldsListView.Items[index + 1];
                        LastView.Tag = SelectGroup.Fields[index + 1];
                        LastView.Text = (LastView.Tag as BillUiFieldsItem).Caption;
                        view.Tag = SelectGroup.Fields[index];
                        view.Text = (view.Tag as BillUiFieldsItem).Caption;
                        LastView.Selected = true;
                        view.Selected = false;
                        SaveStatus = false;
                    }
                }
                else//字段组上组
                {
                    ListViewItem view = FieldsListView.SelectedItems[0];
                    BillUiGroupItems group = view.Tag as BillUiGroupItems;
                    int index = FieldsListView.Items.IndexOf(view);
                    if (index < FieldsListView.Items.Count - 1)
                    {
                        MItem.UiField.moveDown(group);
                        ListViewItem LastView = FieldsListView.Items[index + 1];
                        LastView.Tag = MItem.UiField.FieldsProperties[index + 1];
                        LastView.Text = (LastView.Tag as BillUiGroupItems).Caption;
                        view.Tag = MItem.UiField.FieldsProperties[index];
                        view.Text = (view.Tag as BillUiGroupItems).Caption;
                        LastView.Selected = true;
                        view.Selected = false;
                        SaveStatus = false;
                    }
                }
            }
            moveing = false;
        }


        /// <summary>
        /// 全选
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FieldPopCheckAllNode_Click(object sender, EventArgs e)
        {
            moveing = true;
            HideFieldProperty();
            ListView View = (ListView)PageTabControl.SelectedTabPage.Controls[0];
            if (View.Items.Count > 0)
            {
                for (int i = 0; i < View.Items.Count; i++)
                {
                    ListViewItem it = View.Items[i];
                    it.Selected = true;
                }
            }
            moveing = false;
        }

        private void ParamListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ParamListView.SelectedItems.Count > 0)
            {
                ListViewItem view = ParamListView.SelectedItems[0];
                if (view.Tag is BillMultipleParamItem)
                {
                    AttTabControl.SelectedTabPageIndex = 0;
                    TabChangeControl.SelectedTabPage = GlobalPage;
                    ParamPropertyGrid.SelectedObject = new BillMultipleParamToProperty(view.Tag as BillMultipleParamItem);
                }
            }
        }

        private void ScriptListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ScriptListView.SelectedItems.Count > 0)
            {
                ListViewItem view = ScriptListView.SelectedItems[0];
                if (view.Tag is BillExpandJsCodeItem)
                {
                    BillExpandJsCodeItem it = view.Tag as BillExpandJsCodeItem;
                    AttTabControl.SelectedTabPageIndex = 0;
                    TabChangeControl.SelectedTabPage = JScriptPage;
                    JScriptPropery.SelectField = new BillUiJscriptToProperty(it);
                }
            }
        }


        private void JavaListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (JavaListView.SelectedItems.Count > 0)
            {
                ListViewItem view = JavaListView.SelectedItems[0];
                if (view.Tag is BillExpandJavaCodeItem)
                {
                    BillExpandJavaCodeItem it = view.Tag as BillExpandJavaCodeItem;
                    AttTabControl.SelectedTabPageIndex = 0;
                    TabChangeControl.SelectedTabPage = JavaPage;
                    JavaProperty.SelectObject = new BillUiJavaToProperty(it);
                }
            }
        }

        #endregion


    }
}
